Strict

Import agfx

Global myVDispScreen:TVDispScreen

Class TAgfx_test_app Extends TFramework

	Method OnCreate:Int()
		
		'DEVICE.SetFps(30)		' default FPS is 60
		

		Super.OnCreate()
				
		myVDispScreen = New TVDispScreen		
		myVDispScreen.Prepare()
		
		Return 0
	End
	
	#Rem OPTIONAL 
	
	Method OnUpdate:Int()
		Super.OnUpdate()
	End
	
	Method OnRender:Int()
		Super.OnRender()
			
	End
	
	Method OnResume:Int()
	
	End
	
	Method OnSuspend:Int()
	
	End
	
	Method OnPause:Int()
	
	End
	
	Method OnLoading:Int()
	
	End
	
	#End
	
End


Class TVDispScreen Extends TScreen
	
	' START when app is created
	Method Start:Void()
		DISPLAY.SetVirtualSize(480,320)
	End
	
	' main app logic loop update
	Method Update:Void()

		If KeyDown (KEY_RIGHT) Then DISPLAY.AdjustZoom( 0.01)
		If KeyDown (KEY_LEFT) Then DISPLAY.AdjustZoom( -0.01)
		If KeyDown (KEY_ENTER) Then DISPLAY.SetZoom(1.0)
		
	End
	
	' main app render loop
	Method Render:Void()

		Cls 32, 32, 32
		
		' Corners...
		
		SetColor 255, 0, 0
		DrawRect 0, 0, 32, 32

		SetColor 0, 255, 0
		DrawRect (DISPLAY.VDeviceWidth() - 1) - 32, 0, 32, 32

		SetColor 0, 0, 255
		DrawRect 0, (DISPLAY.VDeviceHeight() - 1) - 32, 32, 32

		SetColor 255, 0, 0
		DrawRect (DISPLAY.VDeviceWidth() - 1) - 32, (DISPLAY.VDeviceHeight() - 1) - 32, 32, 32
		
		' Borders...
		
		SetColor 255, 0, 0
		DrawLine 0, 0, DISPLAY.VDeviceWidth() - 1, 0
		SetColor 0, 255, 0
		DrawLine 0, DISPLAY.VDeviceHeight() - 1, DISPLAY.VDeviceWidth() - 1, DISPLAY.VDeviceHeight() - 1
		SetColor 0, 0, 255
		DrawLine 0, 0, 0, DISPLAY.VDeviceHeight() - 1
		SetColor 255, 255, 0
		DrawLine DISPLAY.VDeviceWidth() - 1, 0, DISPLAY.VDeviceWidth() - 1, DISPLAY.VDeviceHeight() - 1

		' Centre/center...
		
		SetColor 32, 64, 128
		DrawRect (DISPLAY.VDeviceWidth() / 2.0) - 18, (DISPLAY.VDeviceHeight() / 2.0) - 18, 36, 36

		' Mouse...
		
		SetColor 255, 255, 255
		DrawRect DISPLAY.VMouseX() - 16, DISPLAY.VMouseY() - 16, 32, 32

		' Info...
		
		Scale 1, 1
		
		' Note that positions are all multiplied by the scale factor above - had
		' to do this to make things readable!
		
		DrawText "Use LEFT/RIGHT and ENTER to zoom: " + DISPLAY.GetZoom(), 20, 20

		DrawText "Device size: " + DeviceWidth() + " x " + DeviceHeight(), 20, 60
		DrawText "Virtual device size: " + DISPLAY.VDeviceWidth() + " x " + DISPLAY.VDeviceHeight(), 20, 80

		DrawText "Virtual mouse co-ords: " + Int (DISPLAY.VMouseX()) + " x " + Int (DISPLAY.VMouseY()), 20, 200

	End
End

